package com.example.mqttxprovider.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.mqttxprovider.dao.messageMapper;
import com.example.mqttxprovider.service.MessageService;
import com.example.mqttxprovider.vo.dbVO;
import org.springframework.stereotype.Service;

@Service
public class MessageServiceImpl extends ServiceImpl<messageMapper, dbVO> implements MessageService {
    @Override
    public void insertVO(dbVO dbVO) {
        boolean isSuccess = save(dbVO);
        System.out.println(isSuccess);
    }

    @Override
    public String getMsgByTopic(String topic) {
        dbVO dbVO = getOne(new QueryWrapper<dbVO>().eq("topic", topic).orderByDesc("ts"));
        if(dbVO != null){
            return dbVO.getMsg();
        }
        return null;
    }
}
